package com.whjfxx.terminal.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.whjfxx.terminal.base.BaseController;
import com.whjfxx.terminal.biz.param.ImportPageParam;
import com.whjfxx.terminal.biz.param.SearchParam;
import com.whjfxx.terminal.biz.service.PoImportDataService;
import com.whjfxx.terminal.biz.service.PoImportLogService;
import com.whjfxx.terminal.biz.vo.ImportDataVo;
import com.whjfxx.terminal.biz.vo.ImportVo;
import com.whjfxx.terminal.commons.Result;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by b.c on 2022/6/7 16:30
 */
@RestController
@Log4j2
@RequestMapping("import")
public class PoImportController extends BaseController {

    @Autowired
    PoImportDataService poImportDataService;

    @Autowired
    PoImportLogService poImportLogService;

    @GetMapping("page")
    public Result<Page<ImportVo>> pageList(SearchParam<ImportPageParam> param) {
        Page<ImportVo> page = poImportLogService.pageList(param);
        return Result.success(page);
    }

    @GetMapping("data/list")
    public Result<List<ImportDataVo>> subList(@RequestParam("batchNo") String batchNo) {
        List<ImportDataVo> voList = poImportDataService.subList(batchNo);
        return Result.success(voList);
    }

    @PostMapping("import/data")
    public Result<Object> importData(@RequestParam("batchNo") String batchNo) {
        if (StringUtils.isBlank(batchNo)) {
            return Result.fail("参数错误");
        }
        poImportLogService.importData(batchNo);
        return Result.success();
    }
}
